package com.qianyu.project.web.controller.gs;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.qianyu.project.entity.SubBiddingHistory;
import com.qianyu.project.service.ISubBiddingHistroyService;
import com.qianyu.project.utils.Result;
import com.qianyu.project.utils.ResultTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author gs
 * @date create in 2021/2/3 10:30
 */
@RestController
@RequestMapping("/subBiddingHistorys")
public class SubBiddingHistoryController {

    @Autowired
    private ISubBiddingHistroyService subBiddingHistroyService;

    @PostMapping
    public Result save(@RequestBody SubBiddingHistory subBiddingHistory) {
        subBiddingHistroyService.submit(subBiddingHistory);
        return ResultTool.success();
    }

    @GetMapping("/exist/{subId}")
    public Result isExist(@PathVariable String subId) {
        return ResultTool.success(subBiddingHistroyService.isExist(subId));
    }

    @PutMapping
    public Result update(@RequestBody SubBiddingHistory subBiddingHistory) {
        subBiddingHistroyService.update(subBiddingHistory);
        return ResultTool.success();
    }

    @GetMapping("/page")
    public Result getPageList(@RequestParam Map<String, String> params) {
        return ResultTool.success(subBiddingHistroyService.getPageList(params));
    }

    @PutMapping("/operation")
    public Result operation(@RequestBody SubBiddingHistory subBiddingHistory) {
        subBiddingHistroyService.updateById(subBiddingHistory);
        return ResultTool.success();
    }

    @PutMapping("/open/{ids}")
    public Result batchOpen(@PathVariable String ids) {
        SubBiddingHistory subBiddingHistory = new SubBiddingHistory();
        subBiddingHistory.setStatus("2");
        subBiddingHistroyService.update(
                subBiddingHistory,
                new UpdateWrapper<SubBiddingHistory>()
                        .in("id", (Object[]) ids.split(","))
        );
        return ResultTool.success();
    }

    @PutMapping("/cooperation")
    public Result cooperation(@RequestBody SubBiddingHistory subBiddingHistory) {
        subBiddingHistroyService.cooperation(subBiddingHistory);
        return ResultTool.success();
    }
}
